/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanCombatDebut.java
 *
 * Created on 14 janv. 2012, 18:06:09
 */
package InterfaceGraphique.commonPannel;

import InterfaceGraphique.MainApplication;
import cartes.Carte;
import cartes.Monstre;
import common.Constantes;
import java.awt.Font;
import java.awt.Image;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;

/**
 *
 * @author Arthur
 */
public class PanCombatDebut extends javax.swing.JPanel {

    private Monstre monstre;
    
    /** Creates new form PanCombatDebut */
    public PanCombatDebut() {
        this.setBackground(new java.awt.Color(110,48,34));
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lMonstreLvl = new javax.swing.JLabel();
        lJoueurLvl = new javax.swing.JLabel();
        lMessageResult = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lMonstreImage = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(820, 600));
        setPreferredSize(new java.awt.Dimension(820, 600));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setForeground(new java.awt.Color(213, 151, 0));
        jLabel1.setText("Un monstre vous attaque !");
        jLabel1.setName("jLabel1"); // NOI18N
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 40, -1, -1));
        try {
            System.out.println(System.getProperties().get("user.dir"));
            Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/polices/cartoon.ttf"));
            font = font.deriveFont(32.0f);
            this.jLabel1.setFont(font);
        } catch (Exception ex) {
            Logger.getLogger(PanActionInit.class.getName()).log(Level.SEVERE, null, ex);
        }

        jLabel2.setForeground(new java.awt.Color(213, 151, 0));
        jLabel2.setText("Votre force :");
        jLabel2.setName("jLabel2"); // NOI18N
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 160, -1, -1));
        try {
            System.out.println(System.getProperties().get("user.dir"));
            Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/polices/cartoon.ttf"));
            font = font.deriveFont(24.0f);
            this.jLabel2.setFont(font);
        } catch (Exception ex) {
            Logger.getLogger(PanActionInit.class.getName()).log(Level.SEVERE, null, ex);
        }

        jLabel3.setForeground(new java.awt.Color(213, 151, 0));
        jLabel3.setText("Force du monstre :");
        jLabel3.setName("jLabel3"); // NOI18N
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 280, -1, -1));
        try {
            System.out.println(System.getProperties().get("user.dir"));
            Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/polices/cartoon.ttf"));
            font = font.deriveFont(24.0f);
            this.jLabel3.setFont(font);
        } catch (Exception ex) {
            Logger.getLogger(PanActionInit.class.getName()).log(Level.SEVERE, null, ex);
        }

        lMonstreLvl.setForeground(new java.awt.Color(228, 57, 57));
        lMonstreLvl.setText("jLabel4");
        lMonstreLvl.setName("lMonstreLvl"); // NOI18N
        add(lMonstreLvl, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 280, -1, -1));
        try {
            System.out.println(System.getProperties().get("user.dir"));
            Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/polices/cartoon.ttf"));
            font = font.deriveFont(34.0f);
            this.lMonstreLvl.setFont(font);
        } catch (Exception ex) {
            Logger.getLogger(PanActionInit.class.getName()).log(Level.SEVERE, null, ex);
        }

        lJoueurLvl.setForeground(new java.awt.Color(74, 182, 0));
        lJoueurLvl.setText("jLabel4");
        lJoueurLvl.setName("lJoueurLvl"); // NOI18N
        add(lJoueurLvl, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 160, -1, 20));
        try {
            System.out.println(System.getProperties().get("user.dir"));
            Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/polices/cartoon.ttf"));
            font = font.deriveFont(34.0f);
            this.lJoueurLvl.setFont(font);
        } catch (Exception ex) {
            Logger.getLogger(PanActionInit.class.getName()).log(Level.SEVERE, null, ex);
        }

        lMessageResult.setForeground(new java.awt.Color(213, 151, 0));
        lMessageResult.setText("jLabel6");
        lMessageResult.setName("lMessageResult"); // NOI18N
        add(lMessageResult, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 500, -1, -1));
        try {
            System.out.println(System.getProperties().get("user.dir"));
            Font font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/polices/cartoon.ttf"));
            font = font.deriveFont(24.0f);
            this.lMessageResult.setFont(font);
        } catch (Exception ex) {
            Logger.getLogger(PanActionInit.class.getName()).log(Level.SEVERE, null, ex);
        }

        jButton1.setText("jButton1");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 550, 140, 30));

        lMonstreImage.setName("lMonstreImage"); // NOI18N
        add(lMonstreImage, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 30, -1, -1));
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if( MainApplication.getJoueurEnCours().combat(this.monstre) ) {
            // Let's fight !
            System.out.println(monstre);
            ArrayList<Carte> c = MainApplication.getJoueurEnCours().winCombat(this.monstre);            
            MainApplication.showWinCombat(c, this.monstre.getNbNiveaux());
        }
        else { //fuir
            MainApplication.showPerteCombat(this.monstre);          
            
        }
       
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel lJoueurLvl;
    private javax.swing.JLabel lMessageResult;
    private javax.swing.JLabel lMonstreImage;
    private javax.swing.JLabel lMonstreLvl;
    // End of variables declaration//GEN-END:variables

    public void load(Monstre m) {
        this.monstre = m;
        
        this.lMonstreLvl.setText("" + this.monstre.getNiveau());
        this.lJoueurLvl.setText("" + (MainApplication.getJoueurEnCours().getForce()));

        ImageIcon imageCarte = new ImageIcon(getClass().getResource(m.getCheminImage()));
        ImageIcon imageRedim = new ImageIcon(imageCarte.getImage().getScaledInstance(280, 440, Image.SCALE_DEFAULT));
        this.lMonstreImage.setIcon(imageRedim); //         

        if( MainApplication.getJoueurEnCours().combat(this.monstre) )
            // Combat peut etre gagné
        {
            this.lMessageResult.setText("Votre niveau est superieur a celui du monstre, vous gagnez le combat");
//            ImageIcon image2 = new ImageIcon(getClass().getResource("/images/entrerdonjon.png"));
            //ImageIcon imageRedim2 = new ImageIcon(image2.getImage().getScaledInstance(90, 140, Image.SCALE_DEFAULT)); 
//            this.jButton1.setIcon(image2);
            this.jButton1.setText(Constantes.BUTTON_WIN);
        }
        else { // Combat perdu //affichage du bouton: FUIR
            this.lMessageResult.setText("Votre niveau est inferieur a celui du monstre, fuyez !");
            this.jButton1.setText(Constantes.BUTTON_LOSE);
        }
        
        this.validate();
        this.repaint();
       
    }
}
